package com.zhuss.controller.food;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.zhuss.bean.bo.food.product.CreateProductBo;
import com.zhuss.bean.bo.food.product.DeleteProductBo;
import com.zhuss.bean.bo.food.product.DownProductBo;
import com.zhuss.bean.bo.food.product.UpdateProductBo;
import com.zhuss.bean.bo.food.product.UpperProductBo;
import com.zhuss.common.BaseController;
import com.zhuss.common.OperateService;
import com.zhuss.exception.WpsException;
import com.zhuss.food.product.ProductOperateServiceExt;


/**
 * 商品操作 controller
 * @Author zhushanshuo
   @Date 2020/03/01 16:01
 *
 */
  
 
@RestController
@RequestMapping("/product")
public class ProductOperateController extends BaseController {
	
	@Autowired
	@Qualifier("productOperateService")
	private OperateService<Void, Object> productOperateService;
	
	@Autowired
	@Qualifier("productOperateServiceExt")
	private ProductOperateServiceExt productOperateServiceExt;
	
	/**
	 * 创建
	 * @param bo
	 * @throws WpsException
	 */
	@ResponseBody
    @PostMapping("/create")
	@Transactional(rollbackFor = Exception.class)
    public void create(@RequestBody CreateProductBo bo) throws WpsException {
		
		productOperateService.create(bo);
    }
	
	
	/**
	 * 修改
	 * @param bo
	 * @throws WpsException
	 */
	@ResponseBody
    @PostMapping("/update")
    public void update(@RequestBody UpdateProductBo bo) throws WpsException {
		
		productOperateService.update(bo);
    }
	
	/**
	 * 删除
	 * @param bo
	 * @throws WpsException
	 */
	@ResponseBody
    @PostMapping("/delete")
    public void delete(@RequestBody DeleteProductBo bo) throws WpsException {
		
		productOperateService.delete(bo);
    }
	
	
	/**
	 * 启用
	 * @param bo
	 * @throws WpsException
	 */
	@ResponseBody
    @PostMapping("/upper")
    public void upper(@RequestBody UpperProductBo bo) throws WpsException {
		
		productOperateServiceExt.upper(bo);
    }
	
	
	/**
	 * 停用
	 * @param bo
	 * @throws WpsException
	 */
	@ResponseBody
    @PostMapping("/down")
    public void down(@RequestBody DownProductBo bo) throws WpsException {
		
		productOperateServiceExt.down(bo);
    }
	
}
